all: httpd

httpd: libsqlite3.so build_utils httpd.cpp mzroute.h mzroute.cpp mzhttp.h mzhttp.cpp Mzhttpd.h Mzhttpd.cpp
	gcc -W -Wall -o httpd httpd.cpp mzroute.cpp mzhttp.cpp Mzhttpd.cpp utils/*.o -lstdc++ -lpthread -L. -lsqlite3 -Wl,-rpath=.

build_static: libsqlite3.a build_utils httpd.cpp mzroute.h mzroute.cpp mzhttp.h mzhttp.cpp Mzhttpd.h Mzhttpd.cpp
	gcc -W -Wall httpd.cpp mzroute.cpp mzhttp.cpp Mzhttpd.cpp utils/*.o -L./sqlite3 -lsqlite3 -lpthread -ldl -lstdc++ -static -o httpd_static

libsqlite3.a: sqlite3/
	gcc -c sqlite3/sqlite3.c -lpthread -ldl -o sqlite3/sqlite3.o
	ar -r sqlite3/libsqlite3.a sqlite3/sqlite3.o

build_utils: utils/
	gcc -W -Wall -c utils/MzMd5.cpp -o utils/MzMd5.o
	gcc -W -Wall -c utils/MzTime.cpp -o utils/MzTime.o
	gcc -W -Wall -c utils/MzSQL.cpp -o utils/MzSQL.o
	gcc -W -Wall -c utils/MzType2Mime.cpp -o utils/MzType2Mime.o
	gcc -W -Wall -c utils/MzUrl.cpp -o utils/MzUrl.o

run: httpd
	./httpd

libsqlite3.so: sqlite3/sqlite3.c sqlite3/sqlite3.h
	gcc sqlite3/sqlite3.c -lpthread -ldl -fPIC -shared -o libsqlite3.so

sqltest: test.c libsqlite3.so
	gcc -W -Wall test.c -L. -lsqlite3 -Wl,-rpath=. -o test
	
subprocesstest: subprocesstest.cpp
	gcc -W -Wall subprocesstest.cpp -o subprocesstest

NOTE = just push
push:
	make clean
	git add .
	git commit -m "$(NOTE)"
	git push -u origin "master"


clean:
	rm -rf test
	rm -rf subprocesstest
	rm -rf libsqlite3.so
	rm -rf utils/*.o
	rm -rf sqlite3/*.o
	rm -rf sqlite3/*.a
